﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
namespace IHISCETeim.BLL
{
    public class AgentPartOrderController
    {
        public static int Add(AgentPartOrderInfo obj, List<AgentPartOrderDetailInfo> listParts)
        {

            int returnval = AgentPartOrderDAL.Add(obj, listParts);
            if (returnval > 0)
            {
                obj = GetList(returnval);
                SEMailListDAL.Add(AgentEmailController.GetAddPWOrderEmail(obj));
            }
            return returnval;

        }
        public static bool Delete(int OrderId)
        {
            return AgentPartOrderDAL.Delete(OrderId);
        }
        public static AgentPartOrderInfo GetList(int OrderId)
        {
            return CBO.FillObject<AgentPartOrderInfo>(AgentPartOrderDAL.GetList(OrderId));
        }
        public static DataTable GetPagination(string whereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return AgentPartOrderDAL.GetPagination(whereSql, PageIndex, PageSize, Sort, ref TotalCount);
        }
        /// <summary>
        /// 通过审批
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="listParts"></param>
        /// <returns></returns>
        public static bool Update(AgentPartOrderInfo obj, List<AgentPartOrderDetailInfo> listParts)
        {
            bool r = AgentPartOrderDAL.Update(obj, listParts);

            if (r)
            {
                //   obj = GetList(returnval);
                SEMailListDAL.Add(AgentEmailController.GetPassPWOrderEmail(obj.OrderId));
            }
            return r;
        }

        public static bool Edit(AgentPartOrderInfo obj, List<AgentPartOrderDetailInfo> listParts)
        {
            return AgentPartOrderDAL.Update(obj, listParts);
        }

        public static List<AgentPartOrderDetailInfo> GetAllDetailByOrderId(int OrderId)
        {
            return CBO.FillCollection<AgentPartOrderDetailInfo>(AgentPartOrderDAL.GetAllDetailByOrderId(OrderId));
        }

        /// <summary>
        /// 根据用户，获取最后一次配件收件信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static DataTable GetLastAcceptInfo(int UserId)
        {
            return AgentPartOrderDAL.GetLastAcceptInfo(UserId);
        }

        public static bool Cancel(int OrderId)
        {
            return AgentPartOrderDAL.Cancel(OrderId);
        }

        public static bool ReCheck(int OrderId, string ReCheckRemark, string OrderState)
        {
            bool r=  AgentPartOrderDAL.ReCheck(OrderId, ReCheckRemark, OrderState);
            if (r)
            {
                //   obj = GetList(returnval);
                SEMailListDAL.Add(AgentEmailController.GetReCheckPWOrderEmail(OrderId));
            }
            return r;
        }
        /// <summary>
        /// 代理商保外服务支持配件销售明细
        /// </summary>
        /// <param name="sqlwhere"></param>
        /// <returns></returns>
        public static DataTable GetPartListReport(string sqlwhere)
        {
            return AgentPartOrderDAL.GetPartListReport(sqlwhere);
        }
    }
}
